<template>
	<view class="content">
		<view class="bg">
			<view class="continueDay">连续签到：{{getData.continuousCount || 0}}天</view>
			<view class="allDay">
				<view class="allDay1">
					累计签到：{{getData.signCount || 0}}天
				</view>
				<view @click="sign" :class="{'active1':isSignin}" class="signBtn">
					{{ isSignin ? '已签到' : '点击签到'}}
				</view>
			</view>
			<image class="bgimg" src="../static/images/signinBg.png" mode=""></image>
			<view class="riliLogo">
				<image style="width: 45upx;height: 60upx;" class="" src="@/static/images/signin_rili.png" mode=""></image>
				<image style="width: 45upx;height: 60upx;" class="" src="@/static/images/signin_rili.png" mode=""></image>
			</view>
		</view>
		<imt-calendar ref='child' :selected="signData"></imt-calendar>
		<view class="" style="padding:20rpx;">
			<rich-text :nodes="getData.signRule"></rich-text>
		</view>
	</view>
</template>

<script>
	import imtCalendar from '@/member/components/imt-calendar/imt-calendar'
	export default {
		data() {
			return {
				getData:[],
				isSignin:false,
				signData:[]
			}
		},
		onLoad() {
			var date = new Date();
			var mytime=date .toLocaleTimeString(); //获取当前时间
			console.log(mytime)
			this.$util.request({
				url: "/mobile/index.php?act=member_sign&op=index",
				method: 'post',
				data: {},
			}).then((res)=>{
				this.getData=res.datas
				this.isSignin=res.datas.todaySigned
				this.signData=res.datas.signRecord
				uni.setStorageSync('signData',this.signData)				
				if(this.isSignin){
					this.sign=this.sign2
				}
				setTimeout(()=>{					
					this.$refs.child.childFun()
				})
			}).then(()=>{
				var aa=uni.getStorageSync('signData')
				console.log(uni.getStorageSync('signData'))
				
			})
		},
		components: {
			imtCalendar
		},
		methods:{
			getDataFun(){
				this.$util.request({
					url: "/mobile/index.php?act=member_sign&op=index",
					method: 'post',
					data: {},
				}).then((res)=>{
					this.getData=res.datas
					this.isSignin=res.datas.todaySigned
					this.signData=res.datas.signRecord
					console.log(this.signData)
					if(this.isSignin){
						this.sign=this.sign2
					}
					setTimeout(()=>{
						this.$refs.child.childFun()
					})
					
				}).then(()=>{
					// this.$refs.child.childFun()
				})
			},
			sign(){
				this.$util.request({
					url: "/mobile/index.php?act=member_sign&op=sign",
					method: 'post',
					data: {},
				}).then((res)=>{
					if(res.error_code == 0){
						this.isSignin=true
						if(res.datas.voucher){
							uni.showToast({
								title:"恭喜获得"+res.datas.prize_num+"积分"+res.datas.voucher[0].voucher_t_price+"元优惠券,请前往优惠券列表使用",
								icon:"none"
							})
							this.getDataFun()
							return false
						}
						uni.showToast({
							title:"签到成功获得积分"+res.datas.prize_num,
							icon:"none"
						})
						this.getDataFun()
					}else{
						uni.showToast({
							title:res.message,
							icon:"none"
						})
					}
				})
			},
			sign2(){
				uni.showToast({
					title:"今日已经签到了哟～",
					icon:"none"
				})
			}
		}
		
	}
</script>

<style>
	page{
		background: #f2f2f2;
	}
	.content{
		
	}
	.bg{
		position: relative;
		width: 100%;
		height: 350upx;
	}
	.bg .bgimg{
		position: absolute;
		width: 100%;
		height: 350upx;
		left: 0;
		top: 0;
		z-index: 0;		
	}
	.signBtn{
		position: relative;
		z-index: 2;
		width: 182upx;
		height: 60upx;
		line-height: 60upx;
		text-align: center;
		background-color: #FFFFFF;	
		color: #333;
		border-radius: 30upx;
	}
	.bg .active1{
		color:#d92b57;
	}
	.continueDay{
		font-size: 30upx;
		color: #FFFFFF;
		position: relative;
		z-index: 2;
		padding-left: 60upx;
		padding-top: 60upx;
	}
	.allDay{
		padding: 20upx 60upx;
		display: flex;
		justify-content: space-between;
	}
	.allDay1{
		font-size: 30upx;
		color: #FFFFFF;
		position: relative;
		z-index: 2;
	}
	.riliLogo{
		position: relative;
		z-index: 999999999999;
		padding: 50upx 135upx;
		display: flex;
		justify-content: space-between;
	}
</style>